﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;
using He.Common;

namespace He.Web
{
    public partial class form : He.Web.UI.Front
    {
        string rtnUrl = "index.aspx";
        protected void Page_Load(object sender, EventArgs e)
        {
            string act = InputUtil.Get("act");
            if (Request.UrlReferrer != null)
            {
                rtnUrl = Request.UrlReferrer.ToString();
            }
            if (!this.Page.IsPostBack)
            {
                switch (act)
                {
                    case "addFeedback":
                        addFeedback();
                        break;
                    case "addMFeedback":
                        addMFeedback();
                        break;
                    case "addJobApply":
                        addJobApply();
                        break;
                    case "addOrder":
                        addOrder();
                        break;
                    case "addComment":
                        addComment();
                        break;
                }
            }
        }

        //提交意见反馈
        private void addFeedback()
        {
            string title = InputUtil.Form("txtTitle");
            string userName = InputUtil.Form("txtUserName");
            string userEmail = InputUtil.Form("txtEmail");
            string userTel = InputUtil.Form("txtTel");
            string content = InputUtil.Form("txtContent");
            string pos_mark = InputUtil.Form("pos_mark");
            string lang = InputUtil.Form("lang");
            string verify_code = InputUtil.Form("txtVerifycode");
            string result = Validator.VerifyCode(verify_code);
            if (result != "success")
            {
                MsgBox.ShowError(result);
                return;
            }

            Model.feedback model = new Model.feedback();
            model.title = title;
            model.user_name = userName;
            model.user_email = userEmail;
            model.user_tel = userTel;
            model.content = content;
            model.user_qq = "";
            model.add_time = DateTime.Now.ToString();
            model.re_content = "";
            model.re_time = "";
            model.status = (int)Enums.AuditStatus.待审核;
            model.pos_mark = pos_mark;
            model.lang = lang;

            new He.BLL.feedback().Add(model);
            MsgBox.Show("留言提交成功,请等待我们的回复！", rtnUrl);
        }
        //提交意见反馈(手机)
        private void addMFeedback()
        {
            string userName = InputUtil.Form("user_name");
            string content = InputUtil.Form("content");
            string pos_mark = InputUtil.Form("pos_mark");
            string lang = InputUtil.Form("lang");

            Model.feedback model = new Model.feedback();
            model.title = "";
            model.user_name = userName;
            model.user_email = "";
            model.user_tel = "";
            model.content = content;
            model.user_qq = "";
            model.add_time = DateTime.Now.ToString();
            model.re_content = "";
            model.re_time = "";
            model.status = (int)Enums.AuditStatus.待审核;
            model.pos_mark = pos_mark;
            model.lang = lang;

            new He.BLL.feedback().Add(model);
            MsgBox.Show("留言提交成功,请等待我们的回复！", rtnUrl);
        }
        //提交工作申请
        private void addJobApply()
        {
            string jobTitle = InputUtil.Form("txtJobTitle");
            string expectSalary = InputUtil.Form("expectSalary");
            string name = InputUtil.Form("txtName");
            string sex = InputUtil.Form("sex");
            string birthday = InputUtil.Form("txtBirthday");
            string workYear = InputUtil.Form("workYear");
            string marry = InputUtil.Form("marry");
            string address = InputUtil.Form("txtAddress");
            string census = InputUtil.Form("txtCensus");
            string degree = InputUtil.Form("degree");
            string school = InputUtil.Form("txtSchool");
            string speciality = InputUtil.Form("txtSpeciality");
            string phone = InputUtil.Form("txtPhone");
            string email = InputUtil.Form("txtEmail");
            string experience = InputUtil.Form("txtExperience");
            string verify_code = InputUtil.Form("txtVerifycode");
            string result = Validator.VerifyCode(verify_code);
            if (result != "success")
            {
                MsgBox.ShowError(result);
                return;
            }

            Model.resume model = new Model.resume();
            model.job_title = jobTitle;
            model.expect_salary = expectSalary;
            model.name = name;
            model.sex = sex;
            model.birthday = birthday;
            model.work_year = workYear;
            model.marry = marry;
            model.address = address;
            model.census = census;
            model.degree = degree;
            model.school = school;
            model.specialty = speciality;
            model.phone = phone;
            model.email = email;
            model.experience = StringHelper.ClearHtmlTags(experience);
            model.height = "";
            model.grad_year = "";
            model.add_time = DateTime.Now.ToString();
            new He.BLL.resume().Add(model);
            MsgBox.Show("简历提交成功,请等待我们的回复！", rtnUrl);
        }
        //提交在线订单
        private void addOrder()
        {
            string proName = InputUtil.Form("txtProName");
            string quantity = InputUtil.Form("txtQuantity");
            string linkName = InputUtil.Form("txtLinkName");
            string phone = InputUtil.Form("txtPhone");
            string qq = InputUtil.Form("txtQQ");
            string email = InputUtil.Form("txtEmail");
            string address = InputUtil.Form("txtAddress");
            string content = InputUtil.Form("txtContent");
            string pos_mark = InputUtil.Form("pos_mark");
            string lang = InputUtil.Form("lang");
            string verify_code = InputUtil.Form("txtVerifycode");
            string result = Validator.VerifyCode(verify_code);
            if (result != "success")
            {
                MsgBox.ShowError(result);
                return;
            }

            Model.order model = new Model.order();

            model.pro_name = proName;
            model.quantity = int.Parse(quantity);
            model.link_name = linkName;
            model.phone = phone;
            model.qq = qq;
            model.email = email;
            model.address = address;
            model.content = content;
            model.add_time = DateTime.Now.ToString();
            model.pos_mark = pos_mark;
            model.lang = lang;

            model.company_name = "";
            model.tel = "";
            model.fax = "";
            model.order_code = "";

            if (new BLL.order().Add(model) > 0)
            {
                MsgBox.Show("订单提交成功,感谢您的支持！",rtnUrl);
            }
        }
        //提交评论
        private void addComment()
        {
            string verify_code = InputUtil.Form("txtVerifyCode");

            int cid = InputUtil.Form("cid", 0);
            int pid = InputUtil.Form("pid", 0);
            string title = InputUtil.Form("title");
            string content = InputUtil.Form("txtContent");

            string result = Validator.VerifyCode(verify_code);
            if (result != "success")
            {
                MsgBox.ShowError(result);
                return;
            }

            if (cid <= 0 || pid <= 0)
            {
                MsgBox.ShowError("所属栏目或内容不存在");
                return;
            }
            Model.channel channel = new BLL.channel().GetModel(cid);
            string user_name = User.Identity.Name;
            Model.comment comment = new Model.comment();
            comment.channel_id = channel.id;
            comment.pid = pid;
            comment.ptitle = title;
            comment.content = content;
            comment.user_name = string.IsNullOrEmpty(user_name) ? "游客" : user_name;
            comment.add_time = DateTime.Now.ToString();
            comment.is_lock = channel.comment_audit;
            new BLL.comment().Add(comment);
            if (channel.comment_audit == 1)
            {
                MsgBox.Show("评论提交成功，请等待审核！", rtnUrl);
            }
            else
            {
                MsgBox.Show("评论提交成功！", rtnUrl);
            }
        }
    }
}